package cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.service;

import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.entity.Monograph;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.mapper.MonographMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MonographService {
    @Autowired
    private MonographMapper monographMapper;

    public PageInfo<Monograph> get(int pageNum, int pageSize, Monograph monograph) {
        try (com.github.pagehelper.Page<Object> ignored = PageHelper.startPage(pageNum, pageSize)) {
            List<Monograph> monographList = monographMapper.get(monograph);
            return PageInfo.of(monographList);
        }
    }

    public String save(Monograph monograph) {
        if (monographMapper.save(monograph)) {
            return "保存成功";
        }
        return "保存失败";
    }

    public String update(Monograph monograph) {
        if (monographMapper.update(monograph)) {
            return "修改成功";
        }
        return "修改失败";
    }

    public String delete(Long id) {
        if (monographMapper.delete(id)) {
            return "删除成功";
        }
        return "删除失败";
    }
}